package com.tuo51.manager.service.impl;

import com.tuo51.foudation.utils.CopyUtils;
import com.tuo51.manager.domain.SysSetting;
import com.tuo51.manager.repository.SysSettingRepository;
import com.tuo51.manager.service.SysSettingService;
import com.tuo51.manager.vo.SysSettingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SysSettingServiceImpl implements SysSettingService {

    @Autowired
    private SysSettingRepository sysSettingRepository;

    @Override
    public SysSettingVO save(SysSettingVO entityVo) {
        SysSetting s = sysSettingRepository.findTop1By();

        if (s == null){
            s = new SysSetting();
        }

        CopyUtils.copyProperties(entityVo, s);

        sysSettingRepository.save(s);

        SysSettingVO ret = SysSettingVO.of(s);

        return ret;
    }

    @Override
    public SysSettingVO defaultSetting(){
        SysSetting setting = sysSettingRepository.findTop1By();

        SysSettingVO ret = SysSettingVO.of(setting);

        return ret;
    }
}
